package runner.SAPSO_VM;


import runner.jswarm_pso.Particle;
import runner.jswarm_pso.ParticleUpdate;
import runner.jswarm_pso.Swarm;

public class SchedulerParticleUpdate extends ParticleUpdate {
    private static double W = 0.9;
    private static double C = 2.0;
    private static double c1, c2;

    SchedulerParticleUpdate(Particle particle) {
        super(particle);
    }

    //粒子更新
    //速度 位置 局部最优 集群最优
    @Override
    public void update(Swarm swarm, Particle particle) {
        double[] v = particle.getVelocity();
        double[] x = particle.getPosition();
        double[] pbest = particle.getBestPosition();
        double[] gbest = swarm.getBestPosition();

        W = swarm.getInertia();
        c1 = swarm.getC1();
        c2 = swarm.getC2();

        for (int i = 0; i < x.length; ++i) {

            v[i] = W * v[i] + c1 * Math.random() * (pbest[i] - x[i]) + c2 * Math.random() * (gbest[i] - x[i]);
            x[i] = (int) (x[i] + v[i]);
        }

        /* 引入模拟退火*/
        particle.InitMutation();

    }
}